"""
社区视图
"""
from flask import Blueprint, request

from service.CommService import commService

bp = Blueprint("CommSubSys", __name__, url_prefix="/CommSubSys")


@bp.route('/')
def index():
    return {
        "stuatus": 'ok'
    }


# 文章列表
@bp.route('/ArticleList')
def articlelist():
    type = request.args.get('type')
    commservice = commService()
    ds = commservice.articlelist(type)
    dict = {}
    dict['result'] = ds
    return dict


# 搜索文章
@bp.route('/SearchArticle')
def searcharticle():
    str = request.args.get('str')
    commservice = commService()
    ds = commservice.searcharticle(str)
    dict = {}
    dict['result'] = ds
    return dict


# 文章详情
@bp.route('/ArticleDetails')
def toparea():
    aid = request.args.get('aid')
    #获取uid 同时写入该用户的足迹
    uid = request.args.get('uid')
    commservice = commService()
    ds = commservice.articledetails(uid, aid)
    dict = {}
    dict['result'] = ds
    return dict


# 评论文章或求助
@bp.route('/Comment', methods=['GET', 'POST'])
def comment():
    # 获取文章或求助的id 评论者id 和代表类型的type
    id = request.args.get('id')
    uid = request.args.get('uid')
    type = request.args.get('type')
    # 替换成表单接收内容
    content = request.form.get('content', type=str)
    commservice = commService()
    ds = commservice.comment(type, id, uid, content)
    dict = {}
    dict['result'] = ds
    return dict


# 点赞文章
@bp.route('/Like')
def like():
    aid = request.args.get('aid')
    commservice = commService()
    ds = commservice.like(aid)
    dict = {}
    dict['result'] = ds
    return dict


# 求助列表
@bp.route('/HelpList')
def helplist():
    commservice = commService()
    ds = commservice.helplist()
    dict = {}
    dict['result'] = ds
    return dict


# 指定求助列表
@bp.route('/HelpForList')
def helpforlist():
    eid = request.args.get('eid')
    commservice = commService()
    ds = commservice.helpforlist(eid)
    dict = {}
    dict['result'] = ds
    return dict


# 求助详情
@bp.route('/HelpDetails')
def helpdetails():
    hid = request.args.get('hid')
    commservice = commService()
    ds = commservice.helpdetails(hid)
    dict = {}
    dict['result'] = ds
    return dict


# 发布求助
@bp.route('/AddHelp', methods=['GET', 'POST'])
def addhelp():
    title = request.form.get('title')
    # 替换成表单接收内容
    content = request.form.get('content', type=str)
    fromid = request.args.get('fromid')
    commservice = commService()
    ds = commservice.addhelp(title, content, fromid)
    dict = {}
    dict['result'] = ds
    return dict


# 发布定向求助
@bp.route('/AddHelpFor', methods=['GET', 'POST'])
def addhelpfor():
    # 替换成表单接收内容
    title = request.form.get('title')
    # 替换成表单接收内容
    content = request.form.get('content', type=str)

    fromid = request.args.get('fromid')
    toid = request.args.get('toid')
    commservice = commService()
    ds = commservice.addhelpfor(title, content, fromid, toid)
    dict = {}
    dict['result'] = ds
    return dict


# 精品区
@bp.route('/TopArea')
def top():
    type = request.args.get('type')
    commservice = commService()
    ds = commservice.top(type)
    dict = {}
    dict['result'] = ds
    return dict


# 足迹
@bp.route('/Footstep')
def footstep():
    uid = request.args.get('uid')
    commservice = commService()
    ds = commservice.footstep(uid)
    dict = {}
    dict['result'] = ds
    return dict